package cn.fx.order.service.impl;

import cn.fx.basic.service.impl.BaseServiceImpl;
import cn.fx.order.domain.OrderPetAcquisition;
import cn.fx.order.mapper.OrderPetAcquisitionMapper;
import cn.fx.order.service.IOrderPetAcquisitionService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * (OrderPetAcquisition)表服务实现类
 *
 * @author makejava
 * @since 2022-08-10 15:37:25
 */
@Service
//查询的方法比较多，使用查询的事务配置
//只读，事务传播机制=SUPPORTS，有我就用，没有事务就不用
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class OrderPetAcquisitionServiceImpl extends BaseServiceImpl<OrderPetAcquisition> implements IOrderPetAcquisitionService  {

    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;

    /**
     * 无极限树
     *
     * @author makejava
     * @since 2022-08-06 18:34:41
     */
     @Override
    public List<OrderPetAcquisition> deptTree() {
      
        //查询所有
        /*List<OrderPetAcquisition> all = orderPetAcquisitionMapper.loadAll();

        //准备一个map 每次获取父部门都从这里获取
        HashMap<Long, OrderPetAcquisition> map = new HashMap<>();

        //把所有数据放入map中
        for (OrderPetAcquisition orderPetAcquisition : all){
            map.put(orderPetAcquisition.getId(),orderPetAcquisition);
        }

        //准备一个list，保存处理之后的数据: 前端需要得到的集合数据 - 部门树
        List<OrderPetAcquisition> deptTree = new ArrayList<>();
        for(OrderPetAcquisition orderPetAcquisition : all){
            //顶级部门
            if( == null){
                deptTree.add(orderPetAcquisition);
            } else {
                //不是顶级部门  1.想办法找到当前部门的 父部门  获取parent_id
                Long parent_id = orderPetAcquisition.getParent_id();

                //获取上级部门对象: 通过parent_id来找到上级部门, map里面有所有信息
                OrderPetAcquisition parentOrderPetAcquisition = map.get(parent_id);

                //2.将自己装到  父部门 的children中
                parentOrderPetAcquisition.getChildren().add(orderPetAcquisition);
            }
        }
        //返回部门树
        return deptTree;*/
        return null;
    }
}
